package jogo;

import games.patience.control.PatienceGame;
import java.awt.Color;
import javax.swing.JOptionPane;


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrameCardGame.java
 *
 * Created on 30/05/2010, 17:08:38
 */
/**
 *
 * @author fernanda & Igo Amauri
 */
public class FrameCardGame extends javax.swing.JFrame {

    private PatienceGame patienceGame;
    private FrameModality frameMod = new FrameModality();
    public boolean turnOne = true;

    /** Creates new form FrameCardGame */
    public FrameCardGame() {
        initComponents();
        startGame(this.turnOne);

    }

    private void startGame(boolean turnOne) {
        patienceGame = new PatienceGame();
        patienceGame.shareCardsToRegion(turnOne);
        this.showCardsInReserves();
        this.showCardsInDiscard();

    }

    private void setOne() {
        this.turnOne = true;
    }

    private void setThree() {
        this.turnOne = false;
    }

    private void showCardsInFoundations() {

        String cards = "";
        String value = "";
        String nipe = "";
        String prefixoBlack = "<font color='#000000'>";
        String prefixoRed = "<font color='#CD0000'>";

        for (int j = patienceGame.getRegionOfFoundations().getRegion().get(0).getSize() - 1; j >= 0; j--) {

            value = String.valueOf(patienceGame.getRegionOfFoundations().getRegion().get(0).getSetOfCard().get(j).getValue());
            nipe = patienceGame.getRegionOfFoundations().getRegion().get(0).getSetOfCard().get(j).getNipe();


            painelF1.setContentType("text/html");

            if (nipe.equals("heart") || nipe.equals("diamond")) {
                cards += prefixoRed + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
            } else {
                cards += prefixoBlack + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
            }
        }

        painelF1.setText(cards);
        cards = "";

        for (int j = patienceGame.getRegionOfFoundations().getRegion().get(1).getSize() - 1; j >= 0; j--) {

            value = String.valueOf(patienceGame.getRegionOfFoundations().getRegion().get(1).getSetOfCard().get(j).getValue());
            nipe = patienceGame.getRegionOfFoundations().getRegion().get(1).getSetOfCard().get(j).getNipe();


            painelF2.setContentType("text/html");

            if (nipe.equals("heart") || nipe.equals("diamond")) {
                cards += prefixoRed + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
            } else {
                cards += prefixoBlack + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
            }
        }

        painelF2.setText(cards);
        cards = "";

        for (int j = patienceGame.getRegionOfFoundations().getRegion().get(2).getSize() - 1; j >= 0; j--) {

            value = String.valueOf(patienceGame.getRegionOfFoundations().getRegion().get(2).getSetOfCard().get(j).getValue());
            nipe = patienceGame.getRegionOfFoundations().getRegion().get(2).getSetOfCard().get(j).getNipe();


            painelF3.setContentType("text/html");

            if (nipe.equals("heart") || nipe.equals("diamond")) {
                cards += prefixoRed + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
            } else {
                cards += prefixoBlack + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
            }

        }

        painelF3.setText(cards);
        cards = "";

        for (int j = patienceGame.getRegionOfFoundations().getRegion().get(3).getSize() - 1; j >= 0; j--) {

            value = String.valueOf(patienceGame.getRegionOfFoundations().getRegion().get(3).getSetOfCard().get(j).getValue());
            nipe = patienceGame.getRegionOfFoundations().getRegion().get(3).getSetOfCard().get(j).getNipe();


            painelF4.setContentType("text/html");

            if (nipe.equals("heart") || nipe.equals("diamond")) {
                cards += prefixoRed + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
            } else {
                cards += prefixoBlack + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
            }

        }

        painelF4.setText(cards);
        cards = "";




    }

    private void showCardsInReserves() {


        String cards = "";
        String value = "";
        String nipe = "";
        String prefixoBlack = "<font color='#000000'>";
        String prefixoRed = "<font color='#CD0000'>";

        for (int j = patienceGame.getRegionOfReserves().getRegion().get(0).getSize() - 1; j >= 0; j--) {

            value = String.valueOf(patienceGame.getRegionOfReserves().getRegion().get(0).getSetOfCard().get(j).getValue());
            nipe = patienceGame.getRegionOfReserves().getRegion().get(0).getSetOfCard().get(j).getNipe();


            if (patienceGame.getRegionOfReserves().getRegion().get(0).getSetOfCard().get(j).getIsShowed()) {

                painelR1.setContentType("text/html");

                if (nipe.equals("heart") || nipe.equals("diamond")) {
                    cards += prefixoRed + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
                } else {
                    cards += prefixoBlack + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
                }
//
//                cards += String.valueOf(patienceGame.getRegionOfReserves().getRegion().get(0).getSetOfCard().get(j).getValue())
//                        + " " + patienceGame.getRegionOfReserves().getRegion().get(0).getSetOfCard().get(j).getNipe() + "  " + "\n";
            } else {


                cards += prefixoBlack + "----------" + "</font>" + this.fillLineofTextPane("---------");
            }


        }

        painelR1.setText(cards);
        cards = "";

        for (int j = patienceGame.getRegionOfReserves().getRegion().get(1).getSize() - 1; j >= 0; j--) {

            value = String.valueOf(patienceGame.getRegionOfReserves().getRegion().get(1).getSetOfCard().get(j).getValue());
            nipe = patienceGame.getRegionOfReserves().getRegion().get(1).getSetOfCard().get(j).getNipe();


            if (patienceGame.getRegionOfReserves().getRegion().get(1).getSetOfCard().get(j).getIsShowed()) {

                painelR2.setContentType("text/html");

                if (nipe.equals("heart") || nipe.equals("diamond")) {
                    cards += prefixoRed + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
                } else {
                    cards += prefixoBlack + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
                }

            } else {
                cards += prefixoBlack + "----------" + "</font>" + this.fillLineofTextPane("---------");
            }


        }

        painelR2.setText(cards);
        cards = "";


        for (int j = patienceGame.getRegionOfReserves().getRegion().get(2).getSize() - 1; j >= 0; j--) {

            value = String.valueOf(patienceGame.getRegionOfReserves().getRegion().get(2).getSetOfCard().get(j).getValue());
            nipe = patienceGame.getRegionOfReserves().getRegion().get(2).getSetOfCard().get(j).getNipe();


            if (patienceGame.getRegionOfReserves().getRegion().get(2).getSetOfCard().get(j).getIsShowed()) {

                painelR3.setContentType("text/html");

                if (nipe.equals("heart") || nipe.equals("diamond")) {
                    cards += prefixoRed + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
                } else {
                    cards += prefixoBlack + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
                }

            } else {
                cards += prefixoBlack + "----------" + "</font>" + this.fillLineofTextPane("---------");
            }


        }

        painelR3.setText(cards);
        cards = "";

        for (int j = patienceGame.getRegionOfReserves().getRegion().get(3).getSize() - 1; j >= 0; j--) {

            value = String.valueOf(patienceGame.getRegionOfReserves().getRegion().get(3).getSetOfCard().get(j).getValue());
            nipe = patienceGame.getRegionOfReserves().getRegion().get(3).getSetOfCard().get(j).getNipe();


            if (patienceGame.getRegionOfReserves().getRegion().get(3).getSetOfCard().get(j).getIsShowed()) {

                painelR4.setContentType("text/html");

                if (nipe.equals("heart") || nipe.equals("diamond")) {
                    cards += prefixoRed + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
                } else {
                    cards += prefixoBlack + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
                }

            } else {
                cards += prefixoBlack + "----------" + "</font>" + this.fillLineofTextPane("---------");
            }


        }

        painelR4.setText(cards);
        cards = "";

        for (int j = patienceGame.getRegionOfReserves().getRegion().get(4).getSize() - 1; j >= 0; j--) {

            value = String.valueOf(patienceGame.getRegionOfReserves().getRegion().get(4).getSetOfCard().get(j).getValue());
            nipe = patienceGame.getRegionOfReserves().getRegion().get(4).getSetOfCard().get(j).getNipe();


            if (patienceGame.getRegionOfReserves().getRegion().get(4).getSetOfCard().get(j).getIsShowed()) {

                painelR5.setContentType("text/html");

                if (nipe.equals("heart") || nipe.equals("diamond")) {
                    cards += prefixoRed + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
                } else {
                    cards += prefixoBlack + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
                }

            } else {
                cards += prefixoBlack + "----------" + "</font>" + this.fillLineofTextPane("---------");
            }


        }

        painelR5.setText(cards);
        cards = "";


        for (int j = patienceGame.getRegionOfReserves().getRegion().get(5).getSize() - 1; j >= 0; j--) {

            value = String.valueOf(patienceGame.getRegionOfReserves().getRegion().get(5).getSetOfCard().get(j).getValue());
            nipe = patienceGame.getRegionOfReserves().getRegion().get(5).getSetOfCard().get(j).getNipe();


            if (patienceGame.getRegionOfReserves().getRegion().get(5).getSetOfCard().get(j).getIsShowed()) {

                painelR6.setContentType("text/html");

                if (nipe.equals("heart") || nipe.equals("diamond")) {
                    cards += prefixoRed + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
                } else {
                    cards += prefixoBlack + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
                }

            } else {
                cards += prefixoBlack + "----------" + "</font>" + this.fillLineofTextPane("---------");
            }


        }

        painelR6.setText(cards);
        cards = "";

        for (int j = patienceGame.getRegionOfReserves().getRegion().get(6).getSize() - 1; j >= 0; j--) {

            value = String.valueOf(patienceGame.getRegionOfReserves().getRegion().get(6).getSetOfCard().get(j).getValue());
            nipe = patienceGame.getRegionOfReserves().getRegion().get(6).getSetOfCard().get(j).getNipe();


            if (patienceGame.getRegionOfReserves().getRegion().get(6).getSetOfCard().get(j).getIsShowed()) {

                painelR7.setContentType("text/html");

                if (nipe.equals("heart") || nipe.equals("diamond")) {
                    cards += prefixoRed + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
                } else {
                    cards += prefixoBlack + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
                }

            } else {
                cards += prefixoBlack + "----------" + "</font>" + this.fillLineofTextPane("---------");
            }


        }

        painelR7.setText(cards);
        cards = "";



    }

    private void showCardsInDiscard() {

//        painelDiscard.setText(String.valueOf(patienceGame.getRegionOfReserves().getRegion().get(0).getSetOfCard().get(0).getValue())
//                    + " " + patienceGame.getRegionOfReserves().getRegion().get(0).getSetOfCard().get(0).getNipe());


        String cards = "";
        String value = "";
        String nipe = "";
        String prefixoBlack = "<font color='#000000'>";
        String prefixoRed = "<font color='#CD0000'>";

        for (int j = patienceGame.getRegionOfDiscard().getRegion().get(0).getSize() - 1; j >= 0; j--) {

            value = String.valueOf(patienceGame.getRegionOfDiscard().getRegion().get(0).getSetOfCard().get(j).getValue());
            nipe = patienceGame.getRegionOfDiscard().getRegion().get(0).getSetOfCard().get(j).getNipe();


            if (patienceGame.getRegionOfDiscard().getRegion().get(0).getSetOfCard().get(j).getIsShowed()) {

                painelDiscard.setContentType("text/html");

                if (nipe.equals("heart") || nipe.equals("diamond")) {
                    cards += prefixoRed + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
                } else {
                    cards += prefixoBlack + value + nipe + "</font>" + this.fillLineofTextPane(value + nipe);
                }


            }
        }

        painelDiscard.setText(cards);


    }

    public String fillLineofTextPane(String valueENipe) {


        String retorno = "";
        int delimitador = 0;

        if (valueENipe.length() == 1) {
            delimitador = 13;
        }


        if (valueENipe.length() == 9) {
            delimitador = 4;
        }

        //ok
        if (valueENipe.length() == 8) {
            delimitador = 6;
        }

        if (valueENipe.length() == 7) {
            delimitador = 8;
        }

        //ok
        if (valueENipe.length() == 6) {
            delimitador = 10;
        }


        if (valueENipe.length() == 5) {
            delimitador = 12;
        }


        for (int i = 0; i < delimitador; i++) {
            retorno += "&nbsp;";

        }


        return retorno;

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane13 = new javax.swing.JScrollPane();
        painelF1 = new javax.swing.JTextPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        painelF2 = new javax.swing.JTextPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        painelF4 = new javax.swing.JTextPane();
        jScrollPane3 = new javax.swing.JScrollPane();
        painelF3 = new javax.swing.JTextPane();
        jScrollPane4 = new javax.swing.JScrollPane();
        painelDiscard = new javax.swing.JTextPane();
        jScrollPane5 = new javax.swing.JScrollPane();
        painelR7 = new javax.swing.JTextPane();
        jScrollPane7 = new javax.swing.JScrollPane();
        painelR5 = new javax.swing.JTextPane();
        jScrollPane14 = new javax.swing.JScrollPane();
        painelR4 = new javax.swing.JTextPane();
        jScrollPane15 = new javax.swing.JScrollPane();
        painelR1 = new javax.swing.JTextPane();
        jScrollPane8 = new javax.swing.JScrollPane();
        painelR2 = new javax.swing.JTextPane();
        jScrollPane9 = new javax.swing.JScrollPane();
        painelR3 = new javax.swing.JTextPane();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jScrollPane6 = new javax.swing.JScrollPane();
        painelR6 = new javax.swing.JTextPane();
        jScrollPane10 = new javax.swing.JScrollPane();
        painelR8 = new javax.swing.JTextPane();
        jLabel16 = new javax.swing.JLabel();
        jScrollPane11 = new javax.swing.JScrollPane();
        painelDiscard1 = new javax.swing.JTextPane();
        jScrollPane12 = new javax.swing.JScrollPane();
        painelDiscard2 = new javax.swing.JTextPane();
        jScrollPane16 = new javax.swing.JScrollPane();
        painelDiscard3 = new javax.swing.JTextPane();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        value = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        combo1 = new javax.swing.JComboBox();
        combo2 = new javax.swing.JComboBox();
        nipe = new javax.swing.JComboBox();
        mensagem = new javax.swing.JTextField();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jCheckBoxMenuItem1 = new javax.swing.JCheckBoxMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Patience Game");
        setBackground(new java.awt.Color(115, 170, 114));

        jPanel1.setBackground(new java.awt.Color(27, 121, 95));

        painelF1.setEditable(false);
        painelF1.setForeground(new java.awt.Color(15, 17, 14));
        jScrollPane13.setViewportView(painelF1);

        painelF2.setEditable(false);
        jScrollPane1.setViewportView(painelF2);

        painelF4.setEditable(false);
        jScrollPane2.setViewportView(painelF4);

        painelF3.setEditable(false);
        jScrollPane3.setViewportView(painelF3);

        painelDiscard.setEditable(false);
        jScrollPane4.setViewportView(painelDiscard);

        painelR7.setEditable(false);
        jScrollPane5.setViewportView(painelR7);

        painelR5.setEditable(false);
        jScrollPane7.setViewportView(painelR5);

        painelR4.setEditable(false);
        painelR4.setForeground(new java.awt.Color(15, 17, 14));
        jScrollPane14.setViewportView(painelR4);

        painelR1.setEditable(false);
        painelR1.setForeground(new java.awt.Color(15, 17, 14));
        jScrollPane15.setViewportView(painelR1);

        painelR2.setEditable(false);
        jScrollPane8.setViewportView(painelR2);

        painelR3.setEditable(false);
        jScrollPane9.setViewportView(painelR3);

        jLabel1.setText("R1");

        jLabel2.setText("R2");

        jLabel3.setText("R3");

        jLabel4.setText("R4");

        jLabel5.setText("R5");

        jLabel6.setText("R6");

        jLabel7.setText("R7");

        jLabel8.setText("F1");

        jLabel9.setText("F3");

        jLabel10.setText("F2");

        jLabel11.setText("F4");

        jLabel12.setText("Cel 1");

        painelR6.setEditable(false);
        jScrollPane6.setViewportView(painelR6);

        painelR8.setEditable(false);
        jScrollPane10.setViewportView(painelR8);

        jLabel16.setText("R8");

        painelDiscard1.setEditable(false);
        jScrollPane11.setViewportView(painelDiscard1);

        painelDiscard2.setEditable(false);
        jScrollPane12.setViewportView(painelDiscard2);

        painelDiscard3.setEditable(false);
        jScrollPane16.setViewportView(painelDiscard3);

        jLabel17.setText("Cel 2");

        jLabel18.setText("Cel 3");

        jLabel19.setText("Cel 4");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(172, 172, 172)
                .addComponent(jLabel1)
                .addGap(89, 89, 89)
                .addComponent(jLabel2)
                .addGap(100, 100, 100)
                .addComponent(jLabel3)
                .addGap(100, 100, 100)
                .addComponent(jLabel4)
                .addGap(97, 97, 97)
                .addComponent(jLabel5)
                .addGap(103, 103, 103)
                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(86, 86, 86)
                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(85, 85, 85)
                .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(213, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addComponent(jLabel12)
                        .addGap(98, 98, 98)
                        .addComponent(jLabel17)
                        .addGap(89, 89, 89)
                        .addComponent(jLabel18)
                        .addGap(89, 89, 89)
                        .addComponent(jLabel19)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 314, Short.MAX_VALUE)
                        .addComponent(jLabel8)
                        .addGap(96, 96, 96)
                        .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(90, 90, 90)
                        .addComponent(jLabel9)
                        .addGap(52, 52, 52))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jScrollPane15, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jScrollPane9, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jScrollPane14, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jScrollPane11, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jScrollPane12, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jScrollPane16, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jScrollPane10, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jScrollPane13, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(49, 49, 49)
                        .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(49, 49, 49))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE)
                    .addComponent(jScrollPane12, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE)
                    .addComponent(jScrollPane11, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE)
                    .addComponent(jScrollPane16, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jScrollPane13, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(jLabel10)
                            .addComponent(jLabel9)
                            .addComponent(jLabel11))
                        .addGap(48, 48, 48)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jScrollPane10)
                            .addComponent(jScrollPane5, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane6, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane7, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane14, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane9, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane8, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane15, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel12)
                        .addComponent(jLabel17)
                        .addComponent(jLabel18)
                        .addComponent(jLabel19)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 17, Short.MAX_VALUE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 17, Short.MAX_VALUE)
                            .addComponent(jLabel16, javax.swing.GroupLayout.DEFAULT_SIZE, 17, Short.MAX_VALUE))
                        .addGap(22, 22, 22))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5))
                        .addContainerGap())))
        );

        jLabel13.setText("Card");

        jLabel14.setText("From");

        jLabel15.setText("To");

        jButton1.setText("Move");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        combo1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "DISCARD", "F1", "F2", "F3", "F4", "R1", "R2", "R3", "R4", "R5", "R6", "R7" }));

        combo2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "F1", "F2", "F3", "F4", "R1", "R2", "R3", "R4", "R5", "R6", "R7", "DISCARD" }));

        nipe.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "club", "diamond", "heart", "spade" }));

        jMenuBar1.setBackground(new java.awt.Color(115, 170, 114));

        jMenu1.setText("Game");
        jMenu1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu1ActionPerformed(evt);
            }
        });

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F2, 0));
        jMenuItem1.setText("New Game");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jCheckBoxMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));
        jCheckBoxMenuItem1.setText("TurnThreeCards");
        jCheckBoxMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jCheckBoxMenuItem1);

        jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0));
        jMenuItem3.setText("Exit");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Help");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(119, 119, 119)
                .addComponent(jLabel13)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(value, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(nipe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(22, 22, 22)
                .addComponent(jLabel14)
                .addGap(18, 18, 18)
                .addComponent(combo1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(63, 63, 63)
                .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(combo2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(37, 37, 37)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(mensagem, javax.swing.GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE)
                .addGap(136, 136, 136))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(jLabel15)
                    .addComponent(combo1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(combo2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(value, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(nipe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13)
                    .addComponent(jButton1)
                    .addComponent(mensagem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(17, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        if (!patienceGame.moveCard(Integer.parseInt(value.getText()), combo1.getSelectedItem().toString(), combo2.getSelectedItem().toString(), nipe.getSelectedItem().toString()))
            mensagem.setText("Movimento inválido!");
        else
            mensagem.setText("");



        this.showCardsInFoundations();
        this.showCardsInDiscard();
        this.showCardsInReserves();


        if (patienceGame.getRegionOfDiscard().isAnEmptyRegion()
                && patienceGame.getRegionOfReserves().isAnEmptyRegion()) {
            JOptionPane.showMessageDialog(this, "             You Win!!!", "Congratulations", DISPOSE_ON_CLOSE);
        }



    }//GEN-LAST:event_jButton1ActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:
        this.startGame(this.turnOne);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenu1ActionPerformed

    private void jCheckBoxMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxMenuItem1ActionPerformed
        // TODO add your handling code here:
        if (turnOne) {
            this.setThree();
        } else {
            this.setOne();
        }

        this.startGame(turnOne);
    }//GEN-LAST:event_jCheckBoxMenuItem1ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_jMenuItem3ActionPerformed
//    /**
//    * @param args the command line arguments
//    */
//    public static void main(String args[]) {
//
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox combo1;
    private javax.swing.JComboBox combo2;
    private javax.swing.JButton jButton1;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane10;
    private javax.swing.JScrollPane jScrollPane11;
    private javax.swing.JScrollPane jScrollPane12;
    private javax.swing.JScrollPane jScrollPane13;
    private javax.swing.JScrollPane jScrollPane14;
    private javax.swing.JScrollPane jScrollPane15;
    private javax.swing.JScrollPane jScrollPane16;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JTextField mensagem;
    private javax.swing.JComboBox nipe;
    private javax.swing.JTextPane painelDiscard;
    private javax.swing.JTextPane painelDiscard1;
    private javax.swing.JTextPane painelDiscard2;
    private javax.swing.JTextPane painelDiscard3;
    public static javax.swing.JTextPane painelF1;
    private javax.swing.JTextPane painelF2;
    private javax.swing.JTextPane painelF3;
    private javax.swing.JTextPane painelF4;
    public static javax.swing.JTextPane painelR1;
    private javax.swing.JTextPane painelR2;
    private javax.swing.JTextPane painelR3;
    public static javax.swing.JTextPane painelR4;
    private javax.swing.JTextPane painelR5;
    private javax.swing.JTextPane painelR6;
    private javax.swing.JTextPane painelR7;
    private javax.swing.JTextPane painelR8;
    private javax.swing.JTextField value;
    // End of variables declaration//GEN-END:variables
}
